<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class GenWater extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generate:water {--date=} {--num=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'generate water data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $date = $this->option('date');
        if(!$date) {
            $date = date('Y-m-d H:i:s');
        }
        $waterDate = date('Y-m-d H:00:00', strtotime('last hour', strtotime($date)));
        $num = $this->option('num');
        if(!$num) {
            $num = 6;
        }
        $step = 5;
        for($i=0; $i<6; $i++) {
            $interval = $step + $i*floor(60/$num);
            $time = strtotime("+{$interval} minutes", strtotime($waterDate));
            $inputDate = date('Y-m-d H:i:s', $time);
            $this->line($inputDate);
            $this->call('generate:wateraff', [
                "date"=>$inputDate
            ]);
        }
        $this->call('generate:hour', [
                "date"=>$date
        ]);
        
        $this->info('generate water done.......');
    }
}
